package cn.com.surker.lab.util;

import cn.com.surker.util.StringUtils;

/**
 * @Author lucky
 * @create 2025年03月13 20:13
 * @desc 配合比工具类
 */
public class LabLevelUtil {

    /**
     * 水灰比
     * @param sDosage 水
     * @param snDosage 水泥
     * @return
     */
    public static String shRatio(Double sDosage, Double snDosage) {
        if (StringUtils.isNull(sDosage))
            sDosage = 0.0;
        if (StringUtils.isNull(snDosage))
            sDosage = 0.0;
        if (sDosage <= 0 || snDosage <= 0)
            return "0";
        Double ratio = StringUtils.formatDouble(sDosage / snDosage, 2);
        return ratio + "";
    }

    /**
     * 水胶比
     * @param sDosage 水
     * @param snDosage 水泥
     * @param chDosage 参合料
     * @return
     */
    public static String sjRatio(Double sDosage, Double snDosage, Double chDosage) {
        if (StringUtils.isNull(sDosage))
            sDosage = 0.0;
        if (StringUtils.isNull(snDosage))
            sDosage = 0.0;
        if (StringUtils.isNull(chDosage))
            chDosage = 0.0;
        if (sDosage <= 0 || (snDosage + chDosage) <= 0)
            return "0";
        Double ratio = StringUtils.formatDouble(sDosage / (snDosage + chDosage), 2);
        return ratio + "";
    }
    /**
     * 砂率
     * @param xjDosage 细集料
     * @param cjDosage 粗集料
     * @return
     */
    public static Double slRatio(Double xjDosage, Double cjDosage) {
        if (StringUtils.isNull(xjDosage))
            xjDosage = 0.0;
        if (StringUtils.isNull(cjDosage))
            cjDosage = 0.0;
        if (xjDosage <= 0 || cjDosage <= 0)
            return 0.0;
        Double ratio = StringUtils.formatDouble(xjDosage / (xjDosage + cjDosage), 2);
        return ratio;
    }

    /**
     * 配合比
     * @param snDosage 水泥
     * @param xjDosage 细集料
     * @param cjDosage 粗集料
     * @param chDosage 参合料
     * @param wjjDosage 外加剂
     * @param sDosage 水
     * @return
     */
    public static String phbRatio(Double snDosage,Double xjDosage, Double cjDosage, Double chDosage, Double wjjDosage, Double sDosage) {
        if (StringUtils.isNull(snDosage))
            snDosage = 0.0;
        if (StringUtils.isNull(cjDosage))
            cjDosage = 0.0;
        if (StringUtils.isNull(xjDosage))
            xjDosage = 0.0;
        if (StringUtils.isNull(chDosage))
            chDosage = 0.0;
        if (StringUtils.isNull(wjjDosage))
            wjjDosage = 0.0;
        if (StringUtils.isNull(sDosage))
            sDosage = 0.0;
        if (snDosage <= 0)//不存在水泥直接返回
            return "";
        String ratio = "1";
        if (xjDosage > 0)
            ratio += ":" + StringUtils.formatDouble(xjDosage / snDosage, 2);
        else
            ratio += ":0";
        if (cjDosage > 0)
            ratio += ":" + StringUtils.formatDouble(cjDosage / snDosage, 2);
        else
            ratio += ":0";
        if (chDosage > 0)
            ratio += ":" + StringUtils.formatDouble(chDosage / snDosage, 2);
        else
            ratio += ":0";
        if (wjjDosage > 0)
            ratio += ":" + StringUtils.formatDouble(wjjDosage / snDosage, 2);
        else
            ratio += ":0";
        if (sDosage > 0)
            ratio += ":" + StringUtils.formatDouble(sDosage / snDosage, 2);
        else
            ratio += ":0";
        return ratio;
    }
}
